# Author    :Dun_Hz
# Time      :2025-04-07 14:52

def backtracking(element, path, res):
    if visited[element]:
        # 有环
        if element in path:
            start_index=path.index(element)
            res[:]=path[start_index:]
        return

    visited[element]=1
    path.append(element)
    if element in graph:
        for d in graph[element]:
            backtracking(d, path, res)
    path.pop()
    visited[element]=0


n=int(input())
graph= {}
visited= {}
res=[]
for _ in range(n):
    line=list(map(int, input().split()))
    element=line[1]
    dependence=line[2:]
    graph[element]=dependence
    visited[element]=0
    for d in dependence:
        if d not in visited:
            visited[d]=0

for node in graph:
    if not visited[node]:
        backtracking(node, [], res)

startIndex = res.index(min(res))
res= res[startIndex:]+res[:startIndex]
if res and res[0]!=res[-1]:
    res.append(res[0])

print(" ".join(map(str, res)))